<?php
include_once 'app/modul/db/userConnector.php';

class ModulList extends GetData{

	public $daten     = null;
	public $System     = null;
	public $ActivUser  = 0;
	public $expire_time      = 3600;	

	public function __construct($match){
		$this->daten = $match;
	}

	public function getWort(RainTPL $design){
	    $this->design = $design;  
        parent::GetData();
        
	    $Modul = new Db_Modul();  
        if(isset($this->daten["Modul_ID"])){
            if($Modul->aktivModul($this->ActivUser->id,$this->daten["Modul_ID"])){                
			    $pageexplorer = new Db_user_page_explorer();
			    
			    $modulclass = $Modul->getModulSetting($this->daten["Modul_ID"]);
			    
			    include_once 'app/modul/'.$modulclass->Controller.'.php';
			    
			    $modul = new $modulclass->Controller($this->design);
			    
			    $value = $modul->setSetting();	

			    if($value){
    			    $value["modul_nr"] = $this->daten["Modul_ID"];
    			    $value["user_id"] = $this->ActivUser->id;    			    
    			    $pageexplorer->setModul($value);
    			    
    			    HTTP::redirect ( BASE_URL . '/Explorer/543' );	
			    }else{
    			    HTTP::redirect ( BASE_URL . '/Modul/Error/3' );				        
			    }    
            }else{                              
			    HTTP::redirect ( BASE_URL . '/Modul/Error/1' );
            }
        }
        
        if( $cache = $this->design->cache( $this->design->ln.'/modul/modullist',$this->expire_time, $this->ActivUser->id) )
		{
		 	echo $cache;
		}
		else
		{
            
            $this->design->assign ('css', "Modul");
            $this->design->assign ('js', "jsModulList");        
            
            $navi = new Db_user_page_static();
            $navi = $navi->getNavi("Webseiten","Deine Seiten");		
    		$this->design->assign ('navi',$navi);
    
    		$modulList = $Modul->getModulList();
    		
    		foreach ($modulList as $key => $List){		    
    		    $userModul = $Modul->checkIfUserHaveAktiv($this->ActivUser->id,$List->id);
    		    
    		    if(isset($userModul->Date)){
    		        $modulList[$key]->ModulBooked = $userModul->Date;
    		    }
    		}
    		
    		$this->design->assign ('modulList',$modulList);	
    			
		    $this->design->draw( $this->design->ln.'/modul/modullist' );
		}
	}
}
?>